console.log("我是taobaojs");
var name;
var mobile;
var address;

document.getElementsByClassName("modify")[0].click();

//接受消息
chrome.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
        if (request.type == "background_setUserInfo") {
            name = request.name;
            mobile = request.phone;
            address = request.address;

            console.log(name);
            console.log(mobile);
            console.log(address);

            setTaoBaoUserInfo(name, mobile, address);

            sendResponse({farewell: "successful"});
        }else if(request.type=="background_getUserId"){

        }
        sendResponse({farewell: "successful"});
    });



//具体填写网页表格的函数
function setTaoBaoUserInfo(name, mobile, address) {
    if ((name == null) || (name == "") || (mobile == null) ||
        (mobile == "") || (address == null) || (address == "")) {
        alert("请先复制用户信息,再来粘贴.信息此时为空");
    } else {
        copyTextToClipboard(name);
        copyTextToClipboard(mobile);
        copyTextToClipboard(address);
        //此时用户数据没什么问题,尝试更改网页
        var frame = document.getElementsByClassName("add-addr-iframe")[0];
        var innerDoc = frame.contentDocument;
        //点击确认按钮
        innerDoc.getElementsByTagName("button")[0].click();

        setTimeout(function () {
            var buttons= innerDoc.getElementsByTagName("button");
            if(buttons.length!=3){

            }else{
                innerDoc.getElementsByTagName("button")[1].click();
            }
        }, 500);


    }
}